/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.util;

import com.comac.ins.common.core.exception.base.BaseException;
import com.comac.ins.common.core.utils.StringUtils;
import com.comac.ins.isfd.constant.enums.IsfdMeshModelDefinitionLevelEnum;
import com.comac.ins.isfd.domain.bo.IsfdLayupMetalCaseMetaBo;
import com.comac.ins.isfd.domain.bo.IsfdModelGeneralPreprocessBo;
import com.comac.ins.isfd.domain.bo.IsfdModelParametricBo;
import com.comac.ins.isfd.domain.bo.IsfdResultGeneralPreprocessBo;
import com.comac.ins.isfd.domain.thirdParty.IsfdMeshModelStructureDefinitionsQueryThirdPartyBo;
import com.comac.ins.isfd.rpc.xuelang.constants.enums.XueLangRenderFileTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 第三方对接辅助类
 */
@Slf4j
@Component
public class ThirdPartyUtils {

    public void checkMetalCaseParams(IsfdLayupMetalCaseMetaBo bo) {
        if (StringUtils.isBlank(bo.getMaterialCode())) {
            throw new BaseException("材料代码为空，请检查入参。");
        }

        if (StringUtils.isBlank(bo.getSectionNumber())) {
            throw new BaseException("部段代码不能为空，请检查入参。");
        }

        if (bo.getThickness() == null) {
            throw new BaseException("厚度不能为空，请检查入参。");
        }
    }

    public void checkModelGeneralPreprocessBo(IsfdModelGeneralPreprocessBo bo) {
        if (bo == null) {
            throw new BaseException("必填参数未传，请确认后重试！");
        }
        String url = bo.getUrl();
        String fileName = bo.getFileName();
        String filePath = bo.getFilePath();
        String modelNumber = bo.getModelNumber();
        String sectionNumber = bo.getSectionNumber();
        String batchNumber = bo.getBatchNumber();
        if (StringUtils.isEmpty(url)) {
            throw new BaseException("url未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(fileName)) {
            throw new BaseException("fileName未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(filePath)) {
            throw new BaseException("filePath未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(modelNumber)) {
            throw new BaseException("modelNumber未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(sectionNumber)) {
            throw new BaseException("sectionNumber未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(batchNumber)) {
            throw new BaseException("batchNumber未传，请确认后重试！");
        }
    }

    public void checkModelParametricBo(IsfdModelParametricBo bo) {
        if (bo == null) {
            throw new BaseException("必填参数未传，请确认后重试！");
        }
        String url = bo.getUrl();
        String fileName = bo.getFileName();
        String filePath = bo.getFilePath();
        String modelNumber = bo.getModelNumber();
        String sectionNumber = bo.getSectionNumber();
        String batchNumber = bo.getBatchNumber();
        Integer phase = bo.getPhase();
        String indexFileName = bo.getIndexFileName();
        if (StringUtils.isEmpty(url)) {
            throw new BaseException("url未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(fileName)) {
            throw new BaseException("fileName未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(filePath)) {
            throw new BaseException("filePath未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(modelNumber)) {
            throw new BaseException("modelNumber未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(sectionNumber)) {
            throw new BaseException("sectionNumber未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(batchNumber)) {
            throw new BaseException("batchNumber未传，请确认后重试！");
        }
        if (phase == null) {
            throw new BaseException("phase未传，阶段不能为空，请确认后重试！");
        }
        if (XueLangRenderFileTypeEnum.checkFileNameIsZip(fileName) && StringUtils.isBlank(indexFileName)) {
            throw new BaseException("保存文件为zip包，indexFileName索引文件名称（头文件）不能为空，请确认后重试！");
        }
    }

    public void checkResultGeneralPreprocessBo(IsfdResultGeneralPreprocessBo bo) {
        if (bo == null) {
            throw new BaseException("必填参数未传，请确认后重试！");
        }
        String url = bo.getUrl();
        String fileName = bo.getFileName();
        String filePath = bo.getFilePath();
        String modelNumber = bo.getModelNumber();
        String sectionNumber = bo.getSectionNumber();
        String batchNumber = bo.getBatchNumber();
        String roundNumber = bo.getRoundNumber();
        if (StringUtils.isEmpty(url)) {
            throw new BaseException("url未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(fileName)) {
            throw new BaseException("fileName未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(filePath)) {
            throw new BaseException("filePath未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(modelNumber)) {
            throw new BaseException("modelNumber未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(sectionNumber)) {
            throw new BaseException("sectionNumber未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(batchNumber)) {
            throw new BaseException("batchNumber未传，请确认后重试！");
        }
        if (StringUtils.isEmpty(roundNumber)) {
            throw new BaseException("roundNumber未传，请确认后重试！");
        }
    }

    public void checkStructureDefinitionsQueryParams(IsfdMeshModelStructureDefinitionsQueryThirdPartyBo queryThirdPartyBo) {
        Integer level = queryThirdPartyBo.getLevel();
        if (IsfdMeshModelDefinitionLevelEnum.MODEL.getValue().equals(level)) {
            // 什么都不做
        } else if (IsfdMeshModelDefinitionLevelEnum.SECTION.getValue().equals(level)) {
            Long parentId = queryThirdPartyBo.getParentId();
            if (parentId == null) {
                throw new BaseException("level为2时，parentId不能为空，请确认后重试！");
            }
        } else {
            throw new BaseException("level参数错误，请确认后重试！");
        }
    }
}
